package com.aidex.biz.controller;

import java.util.List;
import java.util.UUID;

import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;

import javax.validation.constraints.*;

import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.JinjianFiles;
import com.aidex.biz.service.JinjianFilesService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 进件资料Controller
 *
 * @author sean
 * @email 2074844820@qq.com
 * @date 2025-07-18
 */
@RestController
@RequestMapping("/biz/bizJinjianFiles")
public class JinjianFilesController extends BaseController {
    @Autowired
    private JinjianFilesService jinjianFilesService;

    /**
     * 查询进件资料列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizJinjianFiles:list')")
    @GetMapping("/list")
    public R<PageInfo> list(JinjianFiles jinjianFiles, HttpServletRequest request, HttpServletResponse response) {
        if (SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
            jinjianFiles.setCompanyId(null);
        } else {
            jinjianFiles.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        }
        jinjianFiles.setPage(new PageDomain(request, response));
        return R.data(jinjianFilesService.findPage(jinjianFiles));
    }

    /**
     * 获取进件资料详细信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizJinjianFiles:query')")
    @GetMapping(value = "/{id}")
    public R<JinjianFiles> detail(@PathVariable("id") String id) {
        return R.data(jinjianFilesService.get(id));
    }

    /**
     * 新增进件资料
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizJinjianFiles:add')")
    @Log(title = "进件资料", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated JinjianFiles jinjianFiles) {
        return R.status(jinjianFilesService.save(jinjianFiles));
    }

    /**
     * 新增进件资料
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizJinjianFiles:add')")
    @Log(title = "新增进件资料", businessType = BusinessType.INSERT)
    @PostMapping("/addFiles")
    public R addFiles(@RequestBody @Validated JinjianFiles jinjianFiles) {
        jinjianFiles.setIsNewRecord();
        return R.data(jinjianFilesService.save(jinjianFiles));
    }

    /**
     * 修改进件资料
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizJinjianFiles:edit')")
    @Log(title = "进件资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated JinjianFiles jinjianFiles) {
        return R.status(jinjianFilesService.save(jinjianFiles));
    }


    /**
     * 删除进件资料
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizJinjianFiles:remove')")
    @Log(title = "进件资料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(jinjianFilesService.deleteJinjianFilesByIds(ids));
    }

    /**
     * 获取最大编号
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizJinjianFiles:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort() {
        return R.data(jinjianFilesService.findMaxSort(new JinjianFiles()));
    }

    /**
     * 导出进件资料列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizJinjianFiles:export')")
    @Log(title = "进件资料", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(JinjianFiles jinjianFiles) {

        if (SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
            jinjianFiles.setCompanyId(null);
        } else {
            jinjianFiles.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        }
        List<JinjianFiles> list = jinjianFilesService.findList(jinjianFiles);
        ExcelUtil<JinjianFiles> util = new ExcelUtil<JinjianFiles>(JinjianFiles.class);
        return util.exportExcel(list, "进件资料数据");
    }

}
